﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace PoolKit
{
    internal class FirstElementSelectionStrategy<TResource> : ResourceSelectionStrategy<TResource>
        where TResource:class
    {
        public override Pooled<TResource> Select(IEnumerable<Pooled<TResource>> collection)
        {
            try
            {
                return collection.First();
            }
            catch(ArgumentNullException)
            {
                throw new ArgumentNullException("collection");
            }
            catch(InvalidOperationException)
            {
                throw new CannotSelectResourceException(Resources.CannotSelectFromEmptyCollection);
            }
        }
    }
}